//
// Created by 沈昊 on 2021/12/6.
//
#include <Network/Buffer.h>
#include <Network/TcpServer.h>
#include <Poller/EventPoller.h>
#include <Thread/WorkThreadPool.h>
#include <http/header_fields.hpp>
#include <http/http_header_base.hpp>
#include <http/http_method.hpp>
#include <http/http_response.hpp>
#include <http/http_session.hpp>
#include <http/http_status.hpp>
#include <http/impl/uri_impl.hpp>
#include <http/json_body.hpp>
#include <http/uri.hpp>
#include <http/http_client.hpp>
#include <iostream>
void http_msg() {
  http::http_response<http::json_body> response;
  response.status_code(http::_status::status_code::ok);
  Json::Value value;
  value["name"] = "haoshen";
  value["id"] = 12;
  Json::Value arr;
  arr.append(1);
  arr.append(2);
  response.body()["sldkfsjdlkf"] = 1;
  response.body()["shenhao"] = "is best body";
  response.body()["arr"] = value;
  response.body()["array"] = arr;
  std::cout << *response.to_string() << std::endl;
}
void test_http() {
  using namespace toolkit;
  signal(SIGPIPE, [](int) {});
  Logger::Instance();
  Logger::Instance().add(std::make_shared<ConsoleChannel>());
  Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
  EventPollerPool &pool = EventPollerPool::Instance();

  std::shared_ptr<TcpServer> server(new TcpServer(pool.getFirstPoller()));

  server->start<http::http_session>(9000);
  //退出程序事件处理
  static semaphore sem;
  signal(SIGINT, [](int) { sem.post(); }); // 设置退出信号
  sem.wait();
}
int main() {

  http::uri r("/path/data?name=shenhao&val=11");

  r.path("/userroot?root=123&password=456");

  return 0;
}
